package com.cangshukj.common.core.domain;

import com.cangshukj.common.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

/**
 * 数据导入结果
 * @param <T>
 * @author JiWangli
 */
public class ImportResult<T> {
    /**
     * 成功条数
     */
    private int successNum = 0;
    /**
     * 失败条数
     */
    private int failureNum = 0;

    /**
     * 导入结果信息
     */
    private String message;

    /**
     * 错误数据文件URL
     */
    private String errorUrl;

    /**
     * 错误数据
     */
    @JsonIgnore
    private List<T> errors;

    public ImportResult(int successNum, int failureNum, String message, List<T> errors) {
        this.successNum = successNum;
        this.failureNum = failureNum;
        this.message = message;
        this.errors = errors;
        if(StringUtils.isBlank(message)){
            if(failureNum == 0){
                this.message = "数据已全部导入成功！共 " + successNum + " 条";
            }else{
                this.message = "数据导入完成，其中成功 " +successNum + " 条，失败 " + failureNum +"条.";
            }
        }
    }

    public int getSuccessNum() {
        return successNum;
    }

    public void setSuccessNum(int successNum) {
        this.successNum = successNum;
    }

    public int getFailureNum() {
        return failureNum;
    }

    public void setFailureNum(int failureNum) {
        this.failureNum = failureNum;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorUrl() {
        return errorUrl;
    }

    public void setErrorUrl(String errorUrl) {
        this.errorUrl = errorUrl;
    }

    public List<T> getErrors() {
        return errors;
    }

    public void setErrors(List<T> errors) {
        this.errors = errors;
    }
}
